import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:leader_help/page/task/main/task/models/cell.dart';
import 'package:leader_help/page/task/main/task/models/cell_item.dart';
import 'widgets/cell1.dart';
import 'widgets/section.dart';

import 'package:leader_help/utils/component/list/section.dart';
import 'package:leader_help/utils/util.dart';

import 'index.dart';

class IndustryController extends GetxController
    with GetSingleTickerProviderStateMixin {
  IndustryController();

  final state = IndustryState();

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    super.onInit();
    state.titles = ['按产业', '按门类', '按大类', '按中类', '按小类'];
    state.tabCtrl = TabController(length: state.titles.length, vsync: this);
  }

  void setupData() {
    var md1 = IndustryCellModel(
      title: '2040家企业分布在一、二、三产业，第二产业（工业）企业数相对较多。',
      pic: 'u6357.png'.imgPathTask,
      list: [
        IndustryCellItemModel(
          activeColor: ColorsUtil.red,
          name: '第一产业',
          propertion: '25%',
          count: 510,
        ),
        IndustryCellItemModel(
          activeColor: ColorsUtil.green,
          name: '第二产业',
          propertion: '45%',
          count: 918,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xff3B687E),
          name: '第三产业',
          propertion: '30%',
          count: 612,
        ),
      ],
    );

    var md2 = IndustryCellModel(
      title: '全国20个门类，2040家企业分布在其中16个门类中，其中制造业、农林牧渔业、信息技术业三个门类企业分布数量较多。',
      pic: 'u6387.png'.imgPathTask,
      list: [
        IndustryCellItemModel(
          activeColor: ColorsUtil.red,
          name: '农、林、牧、渔业',
          propertion: '25%',
          count: 510,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xff3B687E),
          name: '采矿业',
          propertion: '2%',
          count: 40,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xffC7DBFB),
          name: '制造业',
          propertion: '35%',
          count: 720,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xffC5F2E2),
          name: '电力热力燃气及水生产和供应业',
          propertion: '1%',
          count: 20,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xffC9D0DB),
          name: '建筑业',
          propertion: '5%',
          count: 102,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xffFBB835),
          name: '批发和零售业',
          propertion: '10%',
          count: 204,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xffFEE9B8),
          name: '住宿和餐饮业',
          propertion: '7%',
          count: 142,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xff41D5A3),
          name: '金融业',
          propertion: '10%',
          count: 204,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xffCFCAFA),
          name: '房地产业',
          propertion: '4%',
          count: 81,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xff59C4E8),
          name: '交通运输、仓储和邮政业',
          propertion: '6%',
          count: 123,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xffCCECCF),
          name: '租赁和商务服务业',
          propertion: '6%',
          count: 123,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xffFEE9B8),
          name: '科学研究和技术',
          propertion: '5%',
          count: 102,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xff915CB2),
          name: '水利、环境管理业',
          propertion: '0%',
          count: 0,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xffCFCAFA),
          name: '居民服务',
          propertion: '0.5%',
          count: 10,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xffCCECCF),
          name: '教育',
          propertion: '0.5%',
          count: 10,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xffFEE9B8),
          name: '信息传输、软件和信息技术服务业',
          propertion: '10%',
          count: 204,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xffFBB835),
          name: '卫生和社会工作',
          propertion: '0%',
          count: 0,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xff3B687E),
          name: '文化、体育和娱乐',
          propertion: '3%',
          count: 61,
        ),
        IndustryCellItemModel(
          activeColor: const Color(0xff41D5A3),
          name: '公共管理',
          propertion: '0%',
          count: 0,
        ),
      ],
    );

    state.dataSource = [
      SectionModel(
          index: 0,
          itemBuilder: (context, index) {
            return IndustryCell1(mod: md1);
          },
          items: [1],
          sectionHeader: IndustrySectionView(title: '按产业分布')),
      SectionModel(
          index: 1,
          itemBuilder: (context, index) {
            return IndustryCell1(mod: md2);
          },
          items: [1],
          sectionHeader: IndustrySectionView(title: '按门类分布（共计20门类）')),
    ];
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    super.onReady();
    setupData();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
    state.tabCtrl.dispose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    super.dispose();
  }
}
